package com.x.wcrm.assemble.control.jaxrs.attachment;

import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WrapBoolean;
import com.x.wcrm.assemble.control.ThisApplication;
import com.x.wcrm.core.entity.Attachment;

class ActionAvailable extends BaseAction {

//	private static Logger logger = LoggerFactory.getLogger(ActionAvailable.class);

	ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			ActionResult<Wo> result = new ActionResult<>();
			Attachment o = emc.find(id, Attachment.class);
			if (null == o) {
				throw new ExceptionAttachmentNotExist(id);
			}
			StorageMapping mapping = ThisApplication.context().storageMappings().get(Attachment.class, o.getStorage());
			Boolean exist = o.existContent(mapping);
			Wo wo = new Wo();
			wo.setValue(exist);
			result.setData(wo);
			return result;
		}
	}

	public static class Wo extends WrapBoolean {

	}

}